package cn.aylog.search;

/**
 * 线性查找
 */
public class LineSearch {
    public static void main(String[] args) {
        int[] arr = {3, 1, 7, 4, 78, -1, 55};
        System.out.println(getIndex(arr, -1));
    }

    public static int getIndex(int[] arr, int tar) {
        int l = arr.length;
        for (int i = 0; i < l; i++) {
            if (arr[i] == tar) {
                return i;
            }
        }
        return -1;
    }
}
